import java.util.List;

public class GenericMaxFinder {

    // 泛型方法，用于找到列表中的最大值
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            throw new IllegalArgumentException("List must not be null or empty");
        }
        T max = list.get(0);
        for (T item : list) {
            if (item.compareTo(max) > 0) {
                max = item;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        // 测试整数列表
        List<Integer> intList = List.of(1, 3, 5, 7, 9);
        Integer maxInt = findMax(intList);
        System.out.println("Max integer: " + maxInt);

        // 测试字符串列表
        List<String> stringList = List.of("apple", "banana", "cherry", "date");
        String maxString = findMax(stringList);
        System.out.println("Max string: " + maxString);
    }
}